// & 和 | 有什么区别

let x: number | string;

x = 123;

x = "abc";

console.log(x);

// | 接口之前进行联合

interface X {
  x: () => string;
  y: () => string;
  name: string;
}

interface Y {
  x: () => string;
  age: number;
  name: string;
}

export type XY = Y & X;

const xy: XY = {
  name: "zhangsan",
  x() {
    return "mmm";
  },
  y() {
    return "abc";
  },
  age: 19,
};

console.log(xy);

// 什么是元组， typeof 的作用
const colors = ["red", "black", "green", "blue"] as const;

let values = ["1", "2", "3", "kkk"] as const; // 这个数组说法是元组(这样定是一种特殊的写法， 即是 元素又是数组)

type myvalues = (typeof values)[number];
type myColors = (typeof colors)[number];

function createDemo(values: myvalues, colors: myColors) {}

createDemo("2", "green");

// 元组是什么？
type yuanzhu = [number, string, boolean];

// 可以约束固定位置的数据类型，且元组可以一直扩展下去；
type t1 = [string, number, ...boolean[]];
type t2 = [string, ...boolean[], number];
type t3 = [...boolean[], string, number];

// 可以把数组转成元组，便签as const

let myarr = [1, 2, 3];

type mytype1 = (typeof myarr)[number]; // number[]

const myarr2 = [1, 2, 3, "zhangsan", false, false];

type mytype2 = (typeof myarr2)[number]; // (number | string | boolean)[] , 获取每一项的类型

let myarr3 = ["age", "name", "1222", "444", 1, 2, 3] as const;
type myTuple = (typeof myarr3)[number]; // 获取只读数组中的每一项值

type TTuple = [string, number, boolean];
const myTestTuple: TTuple = ["yuanyuan", 20, false];

type TTType = typeof myTestTuple;
